home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IFolderCell.m < prev    next >
Text File  |  1993-01-12  |  6KB  |  193 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "IFolderCell.h"
  5. #import "TransparentWindow.h"
  6. #import "IDocTransparentWindow.h"
  7. #import "IReceiveSpeaker.h"
  8. #import "IReceiveListener.h"
  9. #import "IFolderMatrix.h"
  10. #import "errdebug.h"
  11. #import "Localization.h"
  12. #import "data_types.h"
  13. #import <appkit/NXImage.h>
  14. #import <appkit/Panel.h>
  15. #import <dpsclient/dpsNeXT.h>
  16. #import <string.h>
  17. #import <dpsclient/wraps.h>
  18. #import <appkit/graphics.h>
  19.  
  20. #define LoStr(key)      doLocalString(NULL,key,NULL)
  21.  
  22. @implementation IFolderCell
  23.  
  24. - initIconCell:(const char *)iconName
  25. {
  26.     [super initIconCell:iconName];
  27.     [self setTarget:self];
  28.     [self setAction:@selector(selectCellInBrowser:)];
  29.     
  30.     iAltImage = NULL;
  31.     return self;
  32. }
  33.  
  34. - setLeaf:(BOOL)flag
  35. {
  36.     iLeafFlag = flag;
  37.     return self;
  38. }
  39.  
  40. - (BOOL)isLeaf
  41. {
  42.     return (iLeafFlag);
  43. }
  44.  
  45. - drawInside:(const NXRect *)aRect inView:controlView
  46. {
  47.     id        triangle;
  48.     NXPoint    triPoint;
  49.     NXRect    iconFrame;
  50.     NXPoint    iconOrigin;
  51.     
  52.     // do normal stuff
  53.     [super drawInside:aRect inView:controlView];
  54.     
  55.     // draw triangle for directory cell
  56.     if (iLeafFlag == NO) {
  57.     triPoint.x = aRect->size.width - 16.0;
  58.     triPoint.y = (aRect->size.height) / 2;
  59.     triangle = [NXImage findImageNamed:"triangle"];
  60.     [triangle composite:NX_SOVER toPoint:&triPoint];
  61.     }
  62.  
  63.     // draw alternative image (open folder)
  64.     if (iAltImage != NULL) {
  65.     iconFrame = *aRect;
  66.     [self getIconRect:&iconFrame];
  67.     iconOrigin = iconFrame.origin;
  68.     if ([controlView isFlipped] == YES) {
  69.         // control view is Matrix, so usually control view's coordinate
  70.         // is flipped. 
  71.         // reft down corner should be origin for composite view, but
  72.         // reft up corner is {0.0, 0.0} when flipped.
  73.         iconOrigin.y = iconFrame.origin.y + iconFrame.size.height;
  74.     }
  75.     [iAltImage composite:NX_SOVER toPoint:&(iconOrigin)];
  76.     }
  77.  
  78.     return self;
  79. }
  80.  
  81. /* When entering the window, show the Icon being dragged as a ghost in the */
  82. /* well */
  83. - (BOOL)windowEntered:dragSource controlView:cView
  84. {
  85.     id        image;
  86.     NXAtom    closedFolderAtom = NXUniqueString(CLOSEDFOLDER);
  87.     NXAtom    closedMultiFolderAtom = NXUniqueString(CLOSEDMULTIFOLDER);
  88.     NXAtom    nextStationAtom = NXUniqueString(NEXTSTATION);
  89.     NXAtom    selfImageAtom = NXUniqueString([[self image] name]);
  90.     
  91.     if ((image =[dragSource image]) == [NXImage findImageNamed:MIMEDOCICON]) {
  92.     if (selfImageAtom == closedFolderAtom) {
  93.         // dragged window is mime document and this cell has 
  94.         // newsgroup folder
  95.         iAltImage = [NXImage findImageNamed:OPENFOLDER];
  96.     } else if (selfImageAtom == closedMultiFolderAtom) {
  97.         // cell has multi folder
  98.         iAltImage = [NXImage findImageNamed:OPENMULTIFOLDER];
  99.     } else if (selfImageAtom == nextStationAtom) {
  100.         // cell has next station icon
  101.         iAltImage = [NXImage findImageNamed:NEXTALTSTATION];
  102.     } else {
  103.         // default
  104.         return NO;
  105.     }
  106.     [[cView window] disableFlushWindow];
  107.     [cView drawCell:self];
  108.     [[cView window] reenableFlushWindow];
  109.     return YES;
  110.     } else {
  111.     return NO;
  112.     }
  113. }
  114.  
  115. /* When exiting the window, remove the ghost icon from the well */
  116. - (BOOL)windowExited:dragSource controlView:cView
  117. {
  118.     id        image;
  119.     NXAtom    closedFolderAtom = NXUniqueString(CLOSEDFOLDER);
  120.     NXAtom    closedMultiFolderAtom = NXUniqueString(CLOSEDMULTIFOLDER);
  121.     NXAtom    nextStationAtom = NXUniqueString(NEXTSTATION);
  122.     NXAtom    selfImageAtom = NXUniqueString([[self image] name]);
  123.     
  124.     if (((image =[dragSource image]) == [NXImage findImageNamed:MIMEDOCICON]) 
  125.         && ((selfImageAtom == closedFolderAtom) 
  126.             || (selfImageAtom == closedMultiFolderAtom)
  127.             || (selfImageAtom == nextStationAtom))) { 
  128.     // dragged out window is mime document 
  129.     // and this cell has newsgroup folder
  130.     iAltImage = NULL;
  131.     [[cView window] disableFlushWindow];
  132.     [cView drawCell:self];
  133.     [[cView window] reenableFlushWindow];
  134.     return YES;
  135.     } else {
  136.     return NO;
  137.     }
  138. }
  139.  
  140. /* When dropping the Icon in the well, draw it there and message the */
  141. /* delegate so that it can modify the Inspector view accordingly */
  142. - (BOOL)windowDropped:dragSource controlView:cView
  143. {
  144.     id        image;
  145.     port_t      port;
  146.     int         returnCode;
  147.     char    newsgroupName[512];
  148.     NXAtom    closedFolderAtom = NXUniqueString(CLOSEDFOLDER);
  149.     NXAtom    closedMultiFolderAtom = NXUniqueString(CLOSEDMULTIFOLDER);
  150.     NXAtom    nextStationAtom = NXUniqueString(NEXTSTATION);
  151.     NXAtom    selfImageAtom = NXUniqueString([[self image] name]);
  152.     
  153.     if ((image =[dragSource image]) == [NXImage findImageNamed:MIMEDOCICON]) {
  154.     if (selfImageAtom == closedFolderAtom 
  155.         || selfImageAtom == closedMultiFolderAtom 
  156.         || selfImageAtom == nextStationAtom) {
  157.         // dropped window is mime document and this cell has 
  158.         // newsgroup folder or nextStation icon
  159.  
  160.         iAltImage = NULL;    // close folder
  161.         [cView drawCell:self];
  162.         // (char *)title represents newsgroup names
  163.         // if folder is multiple selected, newsgorup name will be 
  164.         // splited by ", ".
  165.         if (selfImageAtom == nextStationAtom) {
  166.         strncpy(newsgroupName, "", 1);
  167.         } else {
  168.         strncpy(newsgroupName, [self title], sizeof(newsgroupName) -1);
  169.         }
  170.     } else {
  171.         return NO;
  172.     }
  173.     
  174.     if ((port = NXPortFromName(MMEDITOR, NULL)) == PORT_NULL) {
  175.         NXRunAlertPanel([self name],LoStr("%s is an unknown port."),
  176.         LoStr("OK"),NULL,NULL, MMEDITOR);
  177.     }
  178.     [[NXApp appSpeaker] setSendPort:port];
  179.     
  180.     if ((returnCode = [[NXApp appSpeaker] 
  181.         requestForPost:(char *)newsgroupName
  182.         sourceWindow:(int)[dragSource sourceWindowNum]]) != 0) {
  183.         NXRunAlertPanel([self name],LoStr("cannot contact %s."),
  184.                 LoStr("OK"), NULL, NULL, MMEDITOR);
  185.     }
  186.     return YES;
  187.     } else {
  188.     return NO;
  189.     }
  190. }
  191.  
  192. @end
  193.